<template>
  <d2-container>
    <template slot="header">{{ header_val }}</template>
    <el-button
      type="primary"
      size="small"
      @click="chooseStrategy()"
      style="margin-bottom:10px;"
    >
      选择策略
    </el-button>
    <el-card shadow="never" class="d2-mb titleline">
      <template slot="header" style="height:66px;">
        <span class="title_x el-button--primary fl"></span>
        <p class="title_l fl">基础信息</p>
      </template>
      <el-form
        class="filter-container"
        ref="egForm"
        :model="egForm"
        :rules="rules"
        label-width="110px"
      >
        <el-row :gutter="20">
          <el-col :span="4">
            <el-form-item label="策略名称" prop="strategy_name">
              <el-input
                placeholder="请输入内容"
                v-model="egForm.strategy_name"
                disabled
              >
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="策略ID" prop="strategy_id">
              <el-input v-model="egForm.strategy_id" disabled> </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="指令类型" prop="command_type">
              <el-select
                v-model="egForm.command_type"
                placeholder="请选择"
                style="width:100%;"
              >
                <el-option
                  v-for="item in type_options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="指令名称" prop="command_name">
              <el-input v-model="egForm.command_name" clearable></el-input>
            </el-form-item>
          </el-col>
          <!-- <el-col :span="4">
            <el-form-item label="指令ID*">
              <el-input placeholder="请输入内容" v-model="egForm.command_id" disabled>
              </el-input>
            </el-form-item>
          </el-col> -->
          <el-col :span="4">
            <el-form-item label="部门名称" prop="department_name">
              <el-select
                v-model="egForm.department_name"
                placeholder="请选择"
                style="width:100%;"
                @change="changeUser()"
              >
                <el-option
                  v-for="item in department_data"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="柜台账户" prop="real_account">
              <el-select
                v-model="egForm.real_account"
                placeholder="请选择"
                style="width:100%;"
              >
                <el-option
                  v-for="item in options_gui"
                  :key="item.RealAccountCode"
                  :label="item.RealAccountName"
                  :value="item.RealAccountCode"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="子账户" prop="sub_account">
              <el-select
                v-model="egForm.sub_account"
                placeholder="请选择"
                style="width:100%;"
              >
                <el-option
                  v-for="item in options_zi"
                  :key="item.LogicAccountCode"
                  :label="item.LogicAccountName"
                  :value="item.LogicAccountCode"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="交易员">
              <el-select
                v-model="egForm.trader"
                placeholder="请选择"
                style="width:100%;"
              >
                <el-option
                  v-for="item in options_user"
                  :key="item.id"
                  :label="item.name"
                  :value="item.name"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="指令开始日期" prop="start_date">
              <el-date-picker
                v-model="egForm.start_date"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="选择日期"
              ></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="指令结束日期" prop="end_date">
              <el-date-picker
                v-model="egForm.end_date"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="选择日期"
              ></el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-card>
    <el-card shadow="never" class="d2-mb titleline">
      <template slot="header" style="height:66px;">
        <span class="title_x el-button--primary fl"></span>
        <p class="title_l fl">交易信息</p>
      </template>
      <el-card shadow="never" class="d2-mb">
        <el-button type="default" size="small" @click="add_row">
          <d2-icon name="plus" />
          增行
        </el-button>
        <el-button
          type="default"
          size="small"
          icon="el-icon-delete"
          @click="del_row"
        >
          删行
        </el-button>
        <div style="margin-top:15px">
          <el-table
            :data="transactionData"
            border
            fit
            :row-class-name="tableRow"
            @selection-change="handleSelectionChange"
            :cell-style="{ 'text-align': 'center' }"
            :header-cell-style="{ 'text-align': 'center' }"
          >
            <el-table-column type="selection" width="40"> </el-table-column>
            <el-table-column type="index" label="序号"> </el-table-column>
            <el-table-column label="品名">
              <template slot-scope="scope">
                <el-input
                  size="small"
                  disabled
                  v-model="scope.row.productName"
                  placeholder="请输入内容"
                ></el-input>
              </template>
            </el-table-column>
            <el-table-column prop="instrument" label="合约" width="240px">
              <template slot-scope="scope">
                <el-input
                  size="small"
                  v-model="scope.row.instrument"
                  disabled
                  placeholder="请输入内容"
                ></el-input>
                <!-- <el-input
                  size="small"
                  style="width: 100px"
                  v-model="scope.row.instrument"
                  disabled
                  placeholder="请输入内容"
                ></el-input>
                <el-button size="small" @click="select_fn(scope.row)"
                  >选择</el-button
                > -->
              </template>
            </el-table-column>
            <el-table-column prop="direction" label="方向" sortable>
              <template slot-scope="scope">
                <el-input
                  size="small"
                  v-model="scope.row.direction"
                  disabled
                  placeholder="请输入内容"
                ></el-input>
                <!-- <el-select
                  v-model="scope.row.direction"
                  disabled
                  placeholder="请选择"
                >
                  <el-option
                    v-for="item in directionSelect"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  >
                  </el-option>
                </el-select> -->
              </template>
            </el-table-column>
            <el-table-column prop="offset_flag" label="开/平" sortable>
              <template slot-scope="scope">
                <el-input
                  size="small"
                  v-model="scope.row.offset_flag"
                  disabled
                  placeholder="请输入内容"
                ></el-input>
                <!-- <el-select
                  v-model="scope.row.offset_flag"
                  disabled
                  placeholder="请选择"
                >
                  <el-option
                    v-for="item in kp"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  >
                  </el-option>
                </el-select> -->
              </template>
            </el-table-column>
            <el-table-column prop="volume" label="手数" sortable>
              <template slot-scope="scope">
                <el-input
                  min="0"
                  type="number"
                  size="small"
                  v-model="scope.row.volume"
                  placeholder="请输入内容"
                ></el-input>
              </template>
            </el-table-column>
            <el-table-column label="成交区间" width="240px">
              <template slot-scope="scope">
                <el-input
                  size="small"
                  style="width: 100px"
                  min="0"
                  type="number"
                  v-model="scope.row.min_price"
                  placeholder="最小值"
                ></el-input>
                --
                <el-input
                  size="small"
                  min="0"
                  type="number"
                  style="width: 100px"
                  v-model="scope.row.max_price"
                  placeholder="最大值
                "
                ></el-input>
              </template>
            </el-table-column>
            <el-table-column prop="commodity_unit" label="单位" sortable>
              <template slot-scope="scope">
                <el-input
                  size="small"
                  disabled
                  v-model="scope.row.commodity_unit"
                ></el-input>
                <!-- <el-select
                  v-model="scope.row.commodity_unit"
                  placeholder="请选择"
                >
                  <el-option
                    v-for="item in dw"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  >
                  </el-option>
                </el-select> -->
              </template>
            </el-table-column>
            <el-table-column prop="currency" label="币种" sortable>
              <template slot-scope="scope">
                <el-input
                  size="small"
                  disabled
                  v-model="scope.row.currency"
                ></el-input>
                <!-- <el-select v-model="scope.row.currency" placeholder="请选择">
                  <el-option
                    v-for="item in bz"
                    :key="item.id"
                    :label="item.name"
                    :value="item.symbol"
                  >
                  </el-option>
                </el-select> -->
              </template>
            </el-table-column>
            <el-table-column prop="name.remarks" label="备注" sortable>
              <template slot-scope="scope">
                <el-input
                  size="small"
                  v-model="scope.row.remarks"
                  placeholder="请输入内容"
                ></el-input>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </el-card>
      <el-button
        type="primary"
        size="small"
        style="float:right;margin:0 0 10px 10px;"
        @click="add_orders_fn"
      >
        保存
      </el-button>
    </el-card>
    <el-dialog
      title="策略明细"
      :visible.sync="dialogVisible_one"
      width="80%"
      :before-close="handleClose"
    >
      <el-table
        :data="dialogVisibleData"
        border
        @selection-change="handleCurrentChange_dialogVisible"
        class="d2-mb"
      >
        <el-table-column
          type="selection"
          :selectable="checkSelectable"
          width="55"
        >
        </el-table-column>
        <el-table-column type="index" label="序号"> </el-table-column>
        <el-table-column prop="type" label="类型" sortable></el-table-column>
        <el-table-column label="品名" sortable>
          <template slot-scope="scope">
            <span v-if="scope.row.type == '现货'">
              {{ scope.row.name.name }}
            </span>
            <span v-if="scope.row.type == '期货'">
              {{ scope.row.productName }}
            </span>
          </template>
        </el-table-column>
        <el-table-column
          prop="instrument"
          label="合约"
          sortable
        ></el-table-column>
        <el-table-column
          prop="direction"
          label="方向"
          sortable
        ></el-table-column>
        <el-table-column
          prop="max_volume"
          label="最大手数"
          sortable
        ></el-table-column>
        <el-table-column
          prop="max_amount"
          label="最大数量"
          sortable
        ></el-table-column>
        <el-table-column
          prop="offset_flag"
          label="开/平"
          sortable
        ></el-table-column>
        <el-table-column
          prop="commodity_unit"
          label="单位"
          sortable
        ></el-table-column>
        <el-table-column prop="market" label="市场" sortable></el-table-column>
        <el-table-column
          prop="currency"
          label="币种"
          sortable
        ></el-table-column>
        <el-table-column
          prop="name.commodity_spot.brand"
          label="品牌"
          sortable
        ></el-table-column>
        <el-table-column
          prop="name.commodity_spot.origin"
          label="产地"
          sortable
        ></el-table-column>
        <el-table-column
          prop="name.commodity_spot.standard"
          label="规格"
          sortable
        ></el-table-column>
        <el-table-column
          prop="name.commodity_spot.attribute"
          label="主属性"
          sortable
        ></el-table-column>
        <el-table-column
          prop="name.remarks"
          label="备注"
          sortable
        ></el-table-column>
      </el-table>
      <el-row class="d2-mb">
        <el-button size="small" @click="dialogVisible_one = false"
          >取 消</el-button
        >
        <el-button
          size="small"
          type="primary"
          @click="submit_dialogVisible_fn(1)"
          >确 定</el-button
        >
      </el-row>
    </el-dialog>
    <el-dialog
      title="策略明细"
      :visible.sync="dialogVisible_two"
      width="80%"
      :before-close="handleClose"
    >
      <el-table
        :data="dialogVisibleData"
        border
        @selection-change="handleCurrentChange_dialogVisible"
        class="d2-mb"
      >
        <el-table-column
          type="selection"
          :selectable="checkSelectable"
          width="55"
        >
        </el-table-column>
        <el-table-column type="index" label="序号"> </el-table-column>
        <el-table-column prop="type" label="类型" sortable></el-table-column>
        <el-table-column label="品名" sortable>
          <template slot-scope="scope">
            <span v-if="scope.row.type == '现货'">
              {{ scope.row.name.name }}
            </span>
            <span v-if="scope.row.type == '期货'">
              {{ scope.row.productName }}
            </span>
          </template>
        </el-table-column>
        <el-table-column
          prop="instrument"
          label="合约"
          sortable
        ></el-table-column>
        <el-table-column
          prop="direction"
          label="方向"
          sortable
        ></el-table-column>
        <el-table-column
          prop="max_volume"
          label="最大手数"
          sortable
        ></el-table-column>
        <el-table-column
          prop="max_amount"
          label="最大数量"
          sortable
        ></el-table-column>
        <el-table-column
          prop="offset_flag"
          label="开/平"
          sortable
        ></el-table-column>
        <el-table-column
          prop="commodity_unit"
          label="单位"
          sortable
        ></el-table-column>
        <el-table-column
          prop="currency"
          label="币种"
          sortable
        ></el-table-column>
        <el-table-column
          prop="name.remarks"
          label="备注"
          sortable
        ></el-table-column>
      </el-table>
      <el-row class="d2-mb">
        <el-button size="small" @click="dialogVisible_two = false"
          >取 消</el-button
        >
        <el-button
          size="small"
          type="primary"
          @click="submit_dialogVisible_fn(2)"
          >确 定</el-button
        >
      </el-row>
    </el-dialog>
    <el-dialog
      title="策略明细"
      :visible.sync="dialogVisible_three"
      width="80%"
      :before-close="handleClose"
    >
      <el-table
        :data="dialogVisibleData"
        border
        @selection-change="handleCurrentChange_dialogVisible"
        class="d2-mb"
      >
        <el-table-column
          type="selection"
          :selectable="checkSelectable"
          width="55"
        >
        </el-table-column>
        <el-table-column type="index" label="序号"> </el-table-column>
        <el-table-column prop="type" label="类型" sortable></el-table-column>
        <el-table-column label="品名" sortable>
          <template slot-scope="scope">
            <span v-if="scope.row.type == '现货'">
              {{ scope.row.name.name }}
            </span>
            <span v-if="scope.row.type == '期货'">
              {{ scope.row.productName }}
            </span>
          </template>
        </el-table-column>
        <el-table-column
          prop="instrument"
          label="合约"
          sortable
        ></el-table-column>
        <el-table-column
          prop="direction"
          label="方向"
          sortable
        ></el-table-column>
        <el-table-column
          prop="max_volume"
          label="最大手数"
          sortable
        ></el-table-column>
        <el-table-column
          prop="max_amount"
          label="最大数量"
          sortable
        ></el-table-column>
        <el-table-column
          prop="offset_flag"
          label="开/平"
          sortable
        ></el-table-column>
        <el-table-column
          prop="commodity_unit"
          label="单位"
          sortable
        ></el-table-column>
        <el-table-column
          prop="currency"
          label="币种"
          sortable
        ></el-table-column>
        <el-table-column
          prop="name.remarks"
          label="备注"
          sortable
        ></el-table-column>
      </el-table>
      <el-row>
        <el-button size="small" @click="dialogVisible_three = false"
          >取 消</el-button
        >
        <el-button
          size="small"
          type="primary"
          @click="submit_dialogVisible_fn(3)"
          >确 定</el-button
        >
      </el-row>
    </el-dialog>
    <!-- 选择合约 -->
    <el-dialog
      title="修改合约"
      :visible.sync="dialogVisible_one_select"
      width="80%"
      :before-close="handleClose"
    >
      <el-table
        :data="dialogVisibleData_select"
        border
        @selection-change="handleCurrentChange_dialogVisible_select"
        class="d2-mb"
      >
        <el-table-column
          type="selection"
          :selectable="checkSelectable"
          width="55"
        >
        </el-table-column>
        <el-table-column type="index" label="序号"> </el-table-column>
        <el-table-column prop="type" label="类型" sortable></el-table-column>
        <el-table-column label="品名" sortable>
          <template slot-scope="scope">
            <span v-if="scope.row.type == '现货'">
              {{ scope.row.name.name }}
            </span>
            <span v-if="scope.row.type == '期货'">
              {{ scope.row.productName }}
            </span>
          </template>
        </el-table-column>
        <el-table-column
          prop="instrument"
          label="合约"
          sortable
        ></el-table-column>
        <el-table-column
          prop="direction"
          label="方向"
          sortable
        ></el-table-column>
        <el-table-column
          prop="max_volume"
          label="最大手数"
          sortable
        ></el-table-column>
        <el-table-column
          prop="max_amount"
          label="最大数量"
          sortable
        ></el-table-column>
        <el-table-column
          prop="offset_flag"
          label="开/平"
          sortable
        ></el-table-column>
        <el-table-column
          prop="commodity_unit"
          label="单位"
          sortable
        ></el-table-column>
        <el-table-column prop="market" label="市场" sortable></el-table-column>
        <el-table-column
          prop="currency"
          label="币种"
          sortable
        ></el-table-column>
        <el-table-column
          prop="name.commodity_spot.brand"
          label="品牌"
          sortable
        ></el-table-column>
        <el-table-column
          prop="name.commodity_spot.origin"
          label="产地"
          sortable
        ></el-table-column>
        <el-table-column
          prop="name.commodity_spot.standard"
          label="规格"
          sortable
        ></el-table-column>
        <el-table-column
          prop="name.commodity_spot.attribute"
          label="主属性"
          sortable
        ></el-table-column>
        <el-table-column
          prop="name.remarks"
          label="备注"
          sortable
        ></el-table-column>
      </el-table>
      <el-row class="d2-mb">
        <el-button size="small" @click="dialogVisible_one_select = false"
          >取 消</el-button
        >
        <el-button
          size="small"
          type="primary"
          @click="submit_dialogVisible_select_fn()"
          >确 定</el-button
        >
      </el-row>
    </el-dialog>
  </d2-container>
</template>

<script>
import {
  getStrategy_trade_info,
  futures_command_info,
  getFutures_command_info,
  getFutures_command_trade,
  getDepartments,
  return_account,
  getUsers,
  currency
} from "@/api/url";
export default {
  data() {
    return {
      header_val: "期权指令-新增",
      rules: {
        strategy_name: [{ required: true, message: "", trigger: "change" }],
        strategy_id: [{ required: true, message: "", trigger: "change" }],
        command_type: [
          { required: true, message: "请选择指令类型", trigger: "change" }
        ],
        command_name: [
          { required: true, message: "请选择指令名称", trigger: "change" }
        ],
        department_name: [
          { required: true, message: "请选择部门名称", trigger: "change" }
        ],
        real_account: [
          { required: true, message: "请选择柜台账户", trigger: "change" }
        ],
        sub_account: [
          { required: true, message: "请选择子账户", trigger: "change" }
        ],
        start_date: [
          { required: true, message: "请选择开始日期", trigger: "change" }
        ],
        end_date: [
          { required: true, message: "请选择结束日期", trigger: "change" }
        ]
      },
      del_status:0,//0为用户没有点击删行 1为用户点击了删行
      options_user: [],
      options_gui: [],
      options_zi: [],
      department_data: [],
      status_routers: this.$route.query.status,
      transactionData: [],
      storeData: {},
      egForm: {
        strategy_name: "",
        strategy_id: "",
        command_type: "",
        command_name: "",
        start_date: "",
        end_date: "",
        department_name: "",
        real_accoun: "",
        sub_account: "",
        trader: "",
        command_id: "",
        jg: "",
        command_trade_type:2
      },
      dialogVisible_one: false,
      dialogVisible_two: false,
      dialogVisible_three: false,
      dialogVisible_one_select: false,
      dialogVisibleData: [],
      currentRow: "",
      currentRow_dialogVisible: [],
      currentRow_dialogVisible_selectData: [],
      dialogVisibleData_select: [],
      delete_selection: [],
      command_type_datas: [
        {
          value: 1,
          label: "现货期货套期"
        },
        {
          value: 2,
          label: "现货现货套期"
        },
        {
          value: 3,
          label: "现货期权套期"
        },
        {
          value: 4,
          label: "期货期货套利"
        },
        {
          value: 5,
          label: "现货单边"
        },
        {
          value: 6,
          label: "期货单边"
        }
      ],
      index_s: "",
      directionSelect: [
        {
          value: 0,
          label: "买入"
        },
        {
          value: 1,
          label: "卖出"
        }
      ],
      kp: [
        {
          value: 0,
          label: "开仓"
        },
        {
          value: 1,
          label: "平仓"
        }
      ],
      bz: [],
      dw: [
        {
          value: 0,
          label: "吨"
        },
        {
          value: 1,
          label: "千克"
        },
        {
          value: 2,
          label: "桶"
        },
        {
          value: 3,
          label: "金属吨"
        },
        {
          value: 4,
          label: "风干吨"
        },
        {
          value: 5,
          label: "手"
        }
      ],
      type_options: [
        {
          value: 1,
          label: "普通指令"
        },
        {
          value: 2,
          label: "调整指令"
        },
        {
          value: 3,
          label: "移仓换月指令"
        }
      ]
    };
  },
  watch: {
    egForm: {
      handler: function(val) {
        if (this.egForm.strategy_id === "") {
          this.$message({
            message: "请先选择策略",
            type: "warning"
          });
        }
      },
      deep: true
    }
  },
  created() {
    currency().then(res => {
      this.bz = res.result.results;
    });
    this.select_gui_zi_fn();
    if (this.$store.getters.selectionStrategy_vue != "") {
      this.egForm.strategy_name = this.$store.getters.selectionStrategy_vue.strategy_name;
      this.egForm.strategy_id = this.$store.getters.selectionStrategy_vue.strategy_id;
    }
    getDepartments().then(res => {
      var shujus = res.result;
      this.department_data = this.treeData(shujus);
    });
    if (this.status_routers != "null" && this.status_routers != undefined) {
      this.header_val = "期权指令-复制";
      var datas = {
        command_id: this.status_routers
      };
      getFutures_command_info(datas).then(res => {
        this.egForm = res.result.results[0];
      });
      getFutures_command_trade(datas).then(res => {
        this.transactionData = res.result.results;
      });
    }
  },
  methods: {
    // 树形菜单扁平化方法
    treeData(tree) {
      var queen = [];
      var out = [];
      queen = queen.concat(tree);
      while (queen.length) {
        var first = queen.shift();
        if (first.sub_depart) {
          queen = queen.concat(first.sub_depart);
          delete first["sub_depart"];
        }
        out.push(first);
      }
      return out;
    },
    //柜台账户 子账号查询
    select_gui_zi_fn() {
      var dda = {
        account_type: "real"
      };
      var aab = {
        account_type: "logic"
      };
      return_account(dda).then(res => {
        this.options_gui = res.result;
      });
      return_account(aab).then(res => {
        this.options_zi = res.result;
      });
      // getUsers().then(res => {
      //   this.options_user = res.result;
      // });
    },
    changeUser(){
      var datas ={
        depart:this.egForm.department_name
      }
      getUsers(datas).then(res => {
        this.options_user = res.result;
      });
    },
    add_row() {
      if (this.egForm.strategy_id === "") {
        this.$message({
          message: "请先选择策略",
          type: "warning"
        });
      } else {
        var datas = {
          strategy_id: this.egForm.strategy_id
        };
        getStrategy_trade_info(datas).then(res => {
          this.dialogVisibleData = res.result;
          this.dialogVisibleData.forEach(item => {
            if (item.name != null) {
              item.name.commodity_spot = item.name.commodity_spot[0];
            }
            this.bz.forEach(iiss => {
              if (iiss.symbol == item.currency) {
                item.currency = iiss.name;
              }
            });
          });
        });
        if (
          this.$store.getters.selectionStrategy_vue.strategy_type ===
          "现货期货套期"
        ) {
          this.dialogVisible_one = true;
        } else if (
          this.$store.getters.selectionStrategy_vue.strategy_type ===
          "期货期货套利"
        ) {
          this.dialogVisible_two = true;
        } else {
          this.dialogVisible_three = true;
        }
      }
    },
    handleClose(done) {
      this.$confirm("确认关闭？")
        .then(_ => {
          done();
        })
        .catch(_ => {});
    },
    tableRow({ row, rowIndex }) {
      row.index = rowIndex;
    },
    select_fn(index) {
      var datas = {
        strategy_id: this.egForm.strategy_id
      };
      getStrategy_trade_info(datas).then(res => {
        this.dialogVisibleData_select = res.result;
        this.dialogVisibleData_select.forEach(item => {
          if (item.name != null) {
            item.name.commodity_spot = item.name.commodity_spot[0];
          }
          this.bz.forEach(bzitem => {
            if (item.currency == bzitem.symbol) {
              item.currency = bzitem.name;
            }
          });
        });
      });
      this.index_s = index.index;
      this.dialogVisible_one_select = true;
    },
    // 单选
    handleCurrentChange_dialogVisible(val) {
      this.currentRow_dialogVisible = val;
      this.currentRow_dialogVisible.minData = "";
      this.currentRow_dialogVisible.maxData = "";
    },
    handleCurrentChange_dialogVisible_select(val) {
      this.currentRow_dialogVisible_selectData = val;
      this.currentRow_dialogVisible_selectData.minData = "";
      this.currentRow_dialogVisible_selectData.maxData = "";
    },
    submit_dialogVisible_fn(index) {
      if (this.currentRow_dialogVisible.length === 0) {
        this.$message({
          message: "请先选择策略明细",
          type: "warning"
        });
      } else if (this.currentRow_dialogVisible.length > 1) {
        this.$message({
          message: "单选",
          type: "warning"
        });
      } else {
        this.currentRow_dialogVisible = this.currentRow_dialogVisible[0];
        for (let i = 0; i < this.transactionData.length; i++) {
          if (this.transactionData[i].id == this.currentRow_dialogVisible.id) {
            this.$message({
              message: "同一条策略明细只能增行一次",
              type: "warning"
            });
            return;
          }
        }
        this.transactionData.push(this.currentRow_dialogVisible);
        if (index === 1) {
          this.dialogVisible_one = false;
        } else if (index === 2) {
          this.dialogVisible_two = false;
        } else {
          this.dialogVisible_three = false;
        }
      }
    },
    submit_dialogVisible_select_fn() {
      if (this.currentRow_dialogVisible_selectData.length === 0) {
        this.$message({
          message: "请先选择策略明细",
          type: "warning"
        });
      } else if (this.currentRow_dialogVisible_selectData.length > 1) {
        this.$message({
          message: "单选",
          type: "warning"
        });
      } else {
        this.currentRow_dialogVisible_selectData.instrument = this.currentRow_dialogVisible_selectData[
          this.index_s
        ].instrument;
        this.dialogVisible_one_select = false;
      }
    },
    del_row() {
      if (this.delete_selection.length != 0) {
        this.del_status=1//记录用户点击了删行
        for (let i = 0; i < this.transactionData.length; i++) {
          for (let index = 0; index < this.delete_selection.length; index++) {
            if (this.transactionData[i].id == this.delete_selection[index].id) {
              this.transactionData.splice(i, 1);
            }
          }
        }
      }
    },
    add_orders_fn() {
      this.$refs["egForm"].validate(valid => {
        if (valid) {
          if (this.transactionData.length == 0) {
            this.$message({
              message: "没有要保存的交易信息",
              type: "warning"
            });
          } else {
            let date111 = new Date(this.egForm.end_date).getTime();
            let date222 = new Date(this.egForm.start_date).getTime();
            if (date111 < date222) {
              this.$message({
                message: "请检测指令结束日期",
                type: "warning"
              });
              return;
            }
            var transactionData_agen = JSON.parse(JSON.stringify(this.transactionData));
            transactionData_agen.forEach(item => {
              if(this.status_routers == null || this.status_routers == undefined || this.del_status==1){
                item.strategy_trade_id = item.id;
              }
              if (item.direction == "买入") {
                item.direction = 0;
              } else if (item.direction == "卖出") {
                item.direction = 1;
              }
              if (item.offset_flag == "开仓") {
                item.offset_flag = 0;
              } else {
                item.offset_flag = 1;
              }
              // if (item.commodity_unit == "吨") {
              //   item.commodity_unit = 0;
              // } else if (item.commodity_unit == "千克") {
              //   item.commodity_unit = 1;
              // } else if (item.commodity_unit == "桶") {
              //   item.commodity_unit = 2;
              // } else if (item.commodity_unit == "金属吨") {
              //   item.commodity_unit = 3;
              // } else if (item.commodity_unit == "风干吨") {
              //   item.commodity_unit = 4;
              // } else if (item.commodity_unit == "手") {
              //   item.commodity_unit = 5;
              // }
              this.bz.forEach(bzitem => {
                if (bzitem.name == item.currency) {
                  item.currency = bzitem.symbol;
                }
              });
            });
            //默认传0 草拟状态
            this.egForm.status = 0;
            // switch (this.egForm.command_type) {
            //   case "普通指令":
            //     this.egForm.command_type = 1;
            //   case "调整指令":
            //     this.egForm.command_type = 2;
            //   case "移仓换月指令":
            //     this.egForm.command_type = 3;
            // }
            if (this.egForm.command_type == "普通指令") {
              this.egForm.command_type = 1;
            } else if (this.egForm.command_type == "调整指令") {
              this.egForm.command_type = 2;
            } else if (this.egForm.command_type == "移仓换月指令") {
              this.egForm.command_type = 3;
            }
            for (var as = 0; as < transactionData_agen.length; as++) {
              if (
                transactionData_agen[as].volume == undefined ||
                transactionData_agen[as].volume == ""
              ) {
                this.$message({
                  message: "手数不能为空",
                  type: "warning"
                });
                return;
              }
              if (
                transactionData_agen[as].max_price == undefined ||
                transactionData_agen[as].min_price == undefined ||
                transactionData_agen[as].max_price == "" ||
                transactionData_agen[as].min_price == ""
              ) {
                this.$message({
                  message: "成交区间不能为空",
                  type: "warning"
                });
                return;
              }
              if (
                transactionData_agen[as].max_price * 1 <
                transactionData_agen[as].min_price * 1
              ) {
                this.$message({
                  message: "成交区间左侧应小于等于右侧",
                  type: "warning"
                });
                return;
              }
            }
            if(transactionData_agen.length>1){
               this.$message({
                  message: "交易信息只能为一条",
                  type: "warning"
                });
                return;
            }
            var datas = {
              operation: "ADD",
              command_info: this.egForm,
              trade_info: transactionData_agen
            };
            futures_command_info(datas)
              .then(res => {
                this.$message({
                  message: res.result,
                  type: "success"
                });
                this.$router.push("/hedging_strategy/order_management");
                this.closeing.closePage(
                  this.$store.getters["d2admin/page/allPage"],
                  this.$store.getters["d2admin/page/currentPage"]
                );
              })
              .catch(err => {
                this.$message.error(err.msg);
              });
          }
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    // 多选
    handleSelectionChange(selection) {
      console.log(this.delete_selection);
      this.delete_selection = selection;
    },
    //选择策略
    chooseStrategy() {
      this.$store.commit("SET_SELECTIONSTRATEGY_VUE", "");
      this.$router.push("/selectionStrategy_two?type="+1); 
    },
    checkSelectable(row) {
      return row.type != "现货";
    }
  }
};
</script>
<style lang="scss">
.resizeNone {
  .el-textarea__inner {
    //el_input中的隐藏属性
    resize: none; //主要是这个样式
  }
}
</style>
